package com.ruoyi.xp.supply.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.xp.supply.constant.SupplyConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.xp.supply.mapper.SupplyWarehouseGoodsMapper;
import com.ruoyi.xp.supply.domain.SupplyWarehouseGoods;
import com.ruoyi.xp.supply.service.ISupplyWarehouseGoodsService;
import com.ruoyi.common.core.text.Convert;

/**
 * 虾皮仓库库存明细Service业务层处理
 * 
 * @author chdx
 * @date 2022-12-29
 */
@Service
public class SupplyWarehouseGoodsServiceImpl implements ISupplyWarehouseGoodsService 
{
    @Autowired
    private SupplyWarehouseGoodsMapper supplyWarehouseGoodsMapper;

    /**
     * 查询虾皮仓库库存明细
     * 
     * @param supplyWarehouseGoodsId 虾皮仓库库存明细主键
     * @return 虾皮仓库库存明细
     */
    @Override
    public SupplyWarehouseGoods selectSupplyWarehouseGoodsBySupplyWarehouseGoodsId(String supplyWarehouseGoodsId)
    {
        return supplyWarehouseGoodsMapper.selectSupplyWarehouseGoodsBySupplyWarehouseGoodsId(supplyWarehouseGoodsId);
    }

    /**
     * 查询虾皮仓库库存明细列表
     * 
     * @param supplyWarehouseGoods 虾皮仓库库存明细
     * @return 虾皮仓库库存明细
     */
    @Override
    public List<SupplyWarehouseGoods> selectSupplyWarehouseGoodsList(SupplyWarehouseGoods supplyWarehouseGoods)
    {
        return supplyWarehouseGoodsMapper.selectSupplyWarehouseGoodsList(supplyWarehouseGoods);
    }

    /**
     * 新增虾皮仓库库存明细
     * 
     * @param supplyWarehouseGoods 虾皮仓库库存明细
     * @return 结果
     */
    @Override
    public int insertSupplyWarehouseGoods(SupplyWarehouseGoods supplyWarehouseGoods)
    {
        return supplyWarehouseGoodsMapper.insertSupplyWarehouseGoods(supplyWarehouseGoods);
    }

    /**
     * 修改虾皮仓库库存明细
     * 
     * @param supplyWarehouseGoods 虾皮仓库库存明细
     * @return 结果
     */
    @Override
    public int updateSupplyWarehouseGoods(SupplyWarehouseGoods supplyWarehouseGoods)
    {
        return supplyWarehouseGoodsMapper.updateSupplyWarehouseGoods(supplyWarehouseGoods);
    }

    /**
     * 批量删除虾皮仓库库存明细
     * 
     * @param supplyWarehouseGoodsIds 需要删除的虾皮仓库库存明细主键
     * @return 结果
     */
    @Override
    public int deleteSupplyWarehouseGoodsBySupplyWarehouseGoodsIds(String supplyWarehouseGoodsIds)
    {
        return supplyWarehouseGoodsMapper.deleteSupplyWarehouseGoodsBySupplyWarehouseGoodsIds(Convert.toStrArray(supplyWarehouseGoodsIds));
    }

    /**
     * 删除虾皮仓库库存明细信息
     * 
     * @param supplyWarehouseGoodsId 虾皮仓库库存明细主键
     * @return 结果
     */
    @Override
    public int deleteSupplyWarehouseGoodsBySupplyWarehouseGoodsId(String supplyWarehouseGoodsId)
    {
        return supplyWarehouseGoodsMapper.deleteSupplyWarehouseGoodsBySupplyWarehouseGoodsId(supplyWarehouseGoodsId);
    }

    /**
     * 通过GoodsSkuId获取库存信息
     *
     * @param goodsSkuId
     * @return
     */
    @Override
    public SupplyWarehouseGoods getByGoodSkuId(Long goodsSkuId) {
        Map<Long, SupplyWarehouseGoods> supplyWarehouseGoodsMap = (Map)CacheUtils.get(SupplyConstant.CACHE_KEY_GOODS);
        if (supplyWarehouseGoodsMap  == null ) {
           List<SupplyWarehouseGoods> supplyWarehouseGoodsList = supplyWarehouseGoodsMapper.selectSupplyWarehouseGoodsList(null);
           supplyWarehouseGoodsMap = new HashMap<>();
           for (SupplyWarehouseGoods supplyWarehouseGoods1 : supplyWarehouseGoodsList) {
               supplyWarehouseGoodsMap.put(supplyWarehouseGoods1.getGoodsSkuId(), supplyWarehouseGoods1);
           }
           CacheUtils.put(SupplyConstant.CACHE_KEY_GOODS, supplyWarehouseGoodsMap);
        }
        return supplyWarehouseGoodsMap.get(goodsSkuId);
    }
}
